ALTER PROCEDURE getBoBasicInfoData
    @begingmt_create DATETIME,
    @endgmt_create DATETIME,
    @PageIndex INT,
    @PageSize INT,
    @TotalCount INT OUTPUT
    --khdm
        ,@khdm NVARCHAR(255)
    --item_code
        ,@item_code NVARCHAR(255)
    --team
        ,@team NVARCHAR(255)
    --print_type
        ,@print_type NVARCHAR(255)
    --bo_status
        ,@bo_status NVARCHAR(255)
AS
BEGIN
    SET NOCOUNT ON;

    -- 计算分页的起始位置
    DECLARE @Offset INT = (@PageIndex - 1) * @PageSize;
--------------------------------------------------------------------------------------------
    SELECT batch_number                    AS 工单号,
           bo_code                         AS MES工单号,
           mest.name                       AS MES订单类型,
           item_code                       AS Item_Code,
           item_category                   AS 产品类别,
           item_length                     AS 产品尺寸长,
           item_width                      AS 产品尺寸宽,
           customer_item_name              AS 客户产品名称,
           customer_code                   AS 客户代码,
           customer_name                   AS 客户名称,
           sub_brand                       AS Sub_Brand,
           planner_code                    AS Planner_code,
           eng                             AS ENG,
           pages                           AS 页数,
           qty                             AS 数量,
           unit                            AS 单位,
           size                            AS Size,
           typesetting_method              AS Typesetting_Method,
           oracle_press_type               AS Oracle_Press_Type,
           mes_presss_type                 AS MES_Press_Type,
           fsc_content                     AS FSC_CONTENT,
           fsc_code                        AS FSC_Code,
           control_level                   AS 受控等级,
           billing_officer                 AS 开单人员,
           so_order_type                   AS SO订单类型,
           ppc_contact                     AS PPC联系人,
           setup_pe                        AS Setup_PE,
           develop_pe                      AS Develop_PE,
           mes_order_create_time           AS 开单日期,
           ppc_recurrence                  AS PPC复期,
           standard_shipping_date          AS 标准出货日期,
           customer_requires_shipping_date AS 客户要求出货日期,
           dept                            AS 部门,
           team                            AS Team,
           color_cert                      AS ColorCert,
           customer_pack_require           AS 客户包装要求,
           inside_pack_require             AS 内部包装要求,
           ppc_dontmore_out                AS PPC勾选请勿多出,
           artwork                         AS Artwork,
           annotationFile.check_path       AS Annotation_File,
           special_instructions            AS 特殊说明,
           cbs_chart                       AS CBS_chart,
           process_card                    AS 工艺卡,
           export_info                     AS 出货资料,
           mdr_special_application         AS MDR及特殊申请表,
           mutable_content_tool            AS 可变内容工具,
           previous_code                   AS 历次编号,
           document_review_status.name     AS 审单状态,
           item_change_content             AS 产品更改内容,
           loss_conversion_coefficient     AS 放损转换系数,
           stepping_id                     AS Stepping_ID,
           indigo_color_composition        AS Indigo_印色成分,
           click                           AS Click,
           production_line                 AS 产线,
           need_flow_ppm                   AS 需流PPM,
           ppm_remark                      AS PPM备注,
           ppm_delivery_remark             AS PPM_出版备注,
           delivery_address                AS 送货地址,
           printer_type                    AS Printer_Type,
           plate_serial_number             AS 搭版流水号,
           gross_discharge_qty             AS 总放数,
           number_of_layouts               AS 排版个数,
           sku_qty                         AS SKU个数,
           dj_qty                          AS DJ个数,
           lot_qty                         AS LOT个数,
           artWork.check_path              AS Artwork文件链接,
           stamps_str                      AS 盖章字符串,
           a.gmt_create                    AS 创建时间,
           a.gmt_modified                  AS 修改时间,
           wh_org                          AS wh_org,
           priority                        AS priority值,
           target_date                     AS targetDate值,
           cust_no                         AS Cust_No,
           data_status                     AS 资料状态,
           scheduling_status               AS 排程状态,
           latest_printing_time            AS 最晚印刷时间,
           zt.name                          AS 工单状态,
           current_site                    AS 当前站点,
           process_line_desc               AS 工序汇总,
           printing_Plate_Required         AS 需印刷版,
           Ink_Required                    AS 需备墨,
           plate_task_status               AS 印刷CTP版任务状态,
           ink_task_status                 AS 备墨任务状态,
           file_task_status                AS 文件制作任务状态,
           site_code                       AS 当前站点代码,
           sub_order                       AS 是否为子单,
           sub_level                       AS 子单当前层级_最多5层,
           parent_bo_id                    AS 父工单,
           team_id                         AS Team_id,
           document_review_status_id       AS 审单状态_id,
           customer_po_number              AS Customer_PO_Number,
           urgent                          AS 是否急单,
           paper_used_num_total            AS 净纸需求总数,
           product_remark                  AS 产品备注,
           replacement_flag                AS 是否为补单,
           front_colors                    AS 正面印色数_正面印色累计个数,
           back_colors                     AS 反面印色数_反面印色累计个数,
           stepping_name                   AS stepping_name,
           mes_order_create_time           AS Header_创建时间
    FROM mes_batch_order a
             left join sys_dict mest on mest.value = a.mes_order_type and mest.type = 'MES_ORDER_TYPE'
             left join dbo.mes_bo_file_check_data artWork on artWork.bo_id = a.id and file_type = 'artworkFile'
             left join dbo.mes_bo_file_check_data annotationFile
                       on annotationFile.bo_id = a.id and annotationFile.file_type = 'annotationFile'
        --审单状态
             left join sys_dict document_review_status on document_review_status.id
        = a.document_review_status_id
             LEFT JOIN
         sys_dict zt ON zt.value = a.status AND zt.type = 'ORDER_STATUS'





------------------------------------------------------------------------------------------------------


    WHERE (@begingmt_create IS NULL OR a.gmt_create >= @begingmt_create)
      AND (@endgmt_create IS NULL OR a.gmt_create <= @endgmt_create)
    --khdm
        AND (@khdm IS NULL OR a.customer_code = @khdm)
    --item_code
        AND (@item_code IS NULL OR a.item_code = @item_code)
    --team
        AND (@team IS NULL OR a.team = @team)
    --print_type
        AND (@print_type IS NULL OR a.printer_type = @print_type)
    --bo_status
      AND (@bo_status IS NULL OR a.status in (SELECT value FROM STRING_SPLIT(@bo_status, ',')))

    order by a.gmt_create desc


    OFFSET @Offset ROWS FETCH NEXT @PageSize ROWS ONLY;

    SELECT @TotalCount = COUNT(1)

    ---------------------------------------------------------------------

    FROM mes_batch_order a
             left join sys_dict mest on mest.value = a.mes_order_type and mest.type = 'MES_ORDER_TYPE'
             left join dbo.mes_bo_file_check_data artWork on artWork.bo_id = a.id and file_type = 'artworkFile'
             left join dbo.mes_bo_file_check_data annotationFile
                       on annotationFile.bo_id = a.id and annotationFile.file_type = 'annotationFile'
        --审单状态
             left join sys_dict document_review_status on document_review_status.id
        = a.document_review_status_id
             LEFT JOIN
         sys_dict zt ON zt.value = a.status AND zt.type = 'ORDER_STATUS'


    -------------------------------------------

    WHERE (@begingmt_create IS NULL OR a.gmt_create >= @begingmt_create)
      AND (@endgmt_create IS NULL OR a.gmt_create <= @endgmt_create)


END